package com.stylefeng.guns.rest.modular.App.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.model.Pager;
import com.stylefeng.guns.rest.Tools.Result;
import com.stylefeng.guns.rest.common.annotion.SSO;
import com.stylefeng.guns.rest.modular.App.model.OrderType;
import com.stylefeng.guns.rest.modular.App.service.IOrderTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
/**
 * 线路类型
 *
 * @author sasazaixian
 * @Date 2018-11-15 14:16
 */
@Controller
@RequestMapping(value = {"/gunsApi/auth/orderType"})
@Api(value = "线路类型操作相关api", tags = {"线路类型操作接口"})
public class OrderTypeController extends BaseController {
    @Autowired
    private IOrderTypeService orderTypeService;
	
    /**
     * 分页获取线路类型列表
     * @param orderType
     * @param pageNum
     * @param pageSize
     * @return	
     */
    @ApiOperation(value = "分页获取线路类型列表", notes = "分页获取线路类型列表", httpMethod = "POST")
    @PostMapping(value = "/pageList", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,consumes= MediaType.APPLICATION_JSON_UTF8_VALUE)	
    @ResponseBody
    @SSO
    public Result pageList(
        @RequestBody @ApiParam(name = "orderType", value = "线路类型对象")OrderType orderType,
        @ApiParam(name = "pageNum", value = "当前页数", required = true) @RequestParam(value = "pageNum", required = true) Integer pageNum,
        @ApiParam(name = "pageSize", value = "每页显示条数", required = true) @RequestParam(value = "pageSize", required = true) Integer pageSize		
        ) {
        try {
            Pager pager=new Pager();
            pager.setPageNumber(pageNum);//页码从1 开始
            pager.setPageSize(pageSize);
            pager.setObj(orderType);			
            return Result.success( orderTypeService.pageListOrderType(pager,getToken()));
        }catch(Exception e){
            return Result.error(e.getMessage(),500100);
        }
    }
    /**
     * 获取线路类型列表
     * @param orderType    
     * @return	
     */
    @ApiOperation(value = "获取线路类型列表", notes = "获取线路类型列表", httpMethod = "POST")
    @PostMapping(value = "/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,consumes= MediaType.APPLICATION_JSON_UTF8_VALUE)	
    @ResponseBody
    @SSO
    public Result list(
        @RequestBody @ApiParam(name = "orderType", value = "线路类型对象")OrderType orderType) {
        try {            
            return Result.success( orderTypeService.selectListOrderType(orderType,getToken()));
        }catch(Exception e){
            return Result.error(e.getMessage(),500100);
        }
    }
    /**
     * 通过主键获取线路类型对象
     * @param id
     * @return
     */
    @ApiOperation(value = "通过主键获取线路类型对象", notes = "通过主键获取线路类型对象", httpMethod = "GET")
    @GetMapping(value = "/getById", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    @SSO
    public Result getById(
            @ApiParam(name = "id", value = "主键ID", required = true) @RequestParam(value = "id", required = true) String  id
    ) {
        try {
            return Result.success( orderTypeService.findOrderTypeById(id,getToken()));
        }catch(Exception e){
            return Result.error(e.getMessage(),500100);
        }
    }

    /**
     * 获取线路类型的Key-Value列表，用于html的Select数据源
     * @param orderType
     * @return
     */
    @ApiOperation(value = "获取线路类型的Key-Value列表，用于html的Select数据源", notes = "获取线路类型的Key-Value列表，用于html的Select数据源", httpMethod = "POST")
    @PostMapping(value = "/optionsList", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,consumes= MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    @SSO
    public Result optionsList(@RequestBody @ApiParam(name = "orderType", value = "线路类型对象")OrderType orderType) {
        try {
            return Result.success(orderTypeService.optionsOrderType(orderType,getToken()));
        }catch(Exception e){
            return Result.error(e.getMessage(),500100);
        }
    }
	private String getToken(){		
		return getHttpServletRequest().getHeader("Authorization").substring(7);
    }
}
